#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

#define inf 0x7f7f7f7f
#define maxn 100411
#define N 500050
#define mod 100003

typedef long long ll;
typedef struct
{
    int u, v, next, w;
} Edge;
Edge e[N];
int cnt, head[N];

inline void add(int u, int v)
{
    e[cnt].u = u;
    e[cnt].v = v;
    // e[cnt].w=w;
    //  e[cnt].f=f;
    e[cnt].next = head[u];
    head[u] = cnt++;
    // e[cnt].u=v;
    //    e[cnt].v=u;
    //    e[cnt].w=0;
    //    e[cnt].f=-f;
    //    e[cnt].next=head[v];
    //    head[v]=cnt++;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

inline int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
struct job
{
    int d, x;
    bool operator<(const job &t) const
    {
        return d > t.d;
    }
};
job j[50050];
int num, n, m, in[50050], top[50050];

void topsort()
{
    priority_queue<job> q;
    for (int i = 1; i <= n; i++)
    {
        if (!in[i])
            q.push(j[i]);
    }
    while (!q.empty())
    {
        job u = q.top();
        q.pop();
        top[num++] = u.x;
        for (int i = head[u.x]; i != -1; i = e[i].next)
        {
            int v = e[i].v;
            in[v]--;
            if (!in[v])
                q.push(j[v]);
        }
    }
    for (int i = 0; i < num - 1; i++)
    {
        cout << top[i] << endl;
    }
    cout << top[num - 1];
}
int main()
{
    cin >> n;
    int p;
    for (int i = 1; i <= n; i++)
    {
        int p;
        cin >> p >> j[i].d;
        j[i].x = i;
    }
    cin >> m;
    int x, y;
    memset(head, -1, sizeof(head));
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &x, &y);
        add(x, y);
        in[y]++;
    }
    topsort();
    return 0;
}